package com.lw.service.impl;

import ch.qos.logback.core.util.StringUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.lw.entity.TbMenu;
import com.lw.mapper.TbMenuMapper;
import com.lw.service.TbMenuService;
import jakarta.annotation.Resource;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务层实现。
 *
 * @author lw
 * @since 2024年08月04日 18:45:46
 */
@Service
@Cacheable(cacheNames ="myEhCache" )
public class TbMenuServiceImpl extends ServiceImpl<TbMenuMapper, TbMenu> implements TbMenuService {
    @Resource
    TbMenuMapper menuMapper;


    /**
     * todo 缓存经典案例
     * cacheNames: myEhCache 缓存库
     * value: 缓存key值
     */
    @Cacheable(value = "getPerms")
    @Override
    public List<String> getPerms(String userId) {
        List<String> list = new ArrayList<>();
        List<TbMenu> tbMenus = menuMapper.selectAll();
        for (TbMenu tbMenu : tbMenus) {
            String perms = tbMenu.getPerms();
            if (StringUtil.isNullOrEmpty(perms)) {
                continue;
            }
            list.add(tbMenu.getPerms());
        }
        return list;
    }
}
